from core.basehandler import BaseHandler
from core.support import set_cutscene
from core.room import Room
from core.action import Action

class SocketGate(Room):
    def __init__(self, room_id):
        Room.__init__(self, room_id)
        self.rune_applied = False
        self.gate_open = False
        
        # build list of actions
        self.add_action(OpenGate)
       
    
    # return description of room.
    def get_description(self):
            return "You see a gate with empty slot in the middle"
    
    # return image of room
    def get_image(self):
        if self.gate_open:
            return "hallway.jpg"
        else:
            return 'tiger_room.JPG'


class GateHandler(BaseHandler):
    
    # return class to use to create a new instance of this room
    def get_room_class(self):
        return SocketGate

# define actions for this room

class OpenGate(Action):
    def __init__(self):
        Action.__init__(self, "open_gate")
    
    def get_description(self):
        return "Try Open Gate"
    
    def do_action(self,game,room,request):
        if room.rune_applied and room.gate_open:
            set_cutscene("The gate is already open")
        elif room.rune_applied:    
            set_cutscene("The stone door is opened, you found two different passages in front of you")
            room.add_action(GoLeft)
            room.add_action(GoRight)
            room.gate_open = True
        else:
            set_cutscene("Nothing happend")
        return
    
    def get_method(self):
        return "get"
    
class GoLeft(Action):
    def __init__(self):
        Action.__init__(self, "go_left")    # do basic initialization for every action
    
    def get_description(self):
        return "Go Left"
    
    def do_action(self,game,room,request):
        return
    
    def get_destination(self):
        return 'swords'

    def get_method(self):
        return "get"
    
class GoRight(Action):
    def __init__(self):
        Action.__init__(self, "go_right")    # do basic initialization for every action
    
    def get_description(self):
        return "Go Right"
    
    def do_action(self,game,room,request):
        return

    def get_destination(self):
        return 'pearls'

    def get_method(self):
        return "get"